package com.dd.common.dto.system.job;

import com.dd.common.pojo.dto.group.CreateGroup;
import com.dd.common.pojo.dto.group.UpdateGroup;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import org.hibernate.validator.constraints.Range;

import javax.validation.constraints.*;
import java.io.Serializable;

/**
 * @author cheng
 */
@Schema(description = "定时任务DTO")
@Data
public class SysJobDTO implements Serializable {

    @Null(message = "ID必须为空", groups = CreateGroup.class)
    @NotNull(message = "ID不能为空", groups = UpdateGroup.class)
    @Schema(description = "ID", example = "1")
    @Min(value = 1, message = "ID必须是正整数")
    private Long id;

    @NotBlank(message = "任务名称不能为空", groups = CreateGroup.class)
    @Schema(description = "任务名称", example = "用户同步任务")
    private String jobName;

    @NotBlank(message = "任务组名不能为空", groups = CreateGroup.class)
    @Schema(description = "任务组名", example = "DEFAULT")
    private String jobGroup;

    @NotBlank(message = "调用目标不能为空", groups = CreateGroup.class)
    @Schema(description = "调用目标", example = "com.example.task.UserSyncTask")
    private String invokeTarget;

    @NotBlank(message = "Cron表达式不能为空", groups = CreateGroup.class)
    @Pattern(regexp = "^\\d+\\s+\\d+\\s+\\d+\\s+\\d+\\s+\\d+$", message = "Cron表达式格式不正确")
    @Schema(description = "Cron表达式", example = "0 0 0/1 * * ?")
    private String cronExpression;

    @Schema(description = "错失触发策略：1-立即触发，2-忽略", example = "1")
    @Range(min = 1, max = 2, message = "错失触发策略值只能是1或2")
    private Integer misfirePolicy;

    @Schema(description = "是否允许并发：0-否，1-是", example = "1")
    @Range(min = 0, max = 1, message = "是否允许并发值只能是0或1")
    private Integer concurrent;

    @Schema(description = "状态：0-暂停，1-正常", example = "1")
    @Range(min = 0, max = 1, message = "状态值只能是0或1")
    private Integer status;
}
